package xyz.zxcwxy999.news.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import xyz.zxcwxy999.news.entity.Comment;
import xyz.zxcwxy999.news.entity.News;
import xyz.zxcwxy999.news.service.CommentService;

@RestController
public class CommentController {
    @Autowired
    CommentService commentService;

    @GetMapping("/comment/{id}")
    public JSONObject getOne(@PathVariable("id") int nid) {
        Comment[] comment = commentService.getAllComments(nid);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("object", comment);
        return jsonObject;
    }
    @PostMapping("/comment/add")
    public JSONObject addOne(@RequestBody Comment comment){
        boolean result=commentService.addOneComment(comment)==1?true:false;
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("isok",result);
        return jsonObject;
    }

}
